package org.example.myleet.p1725;

import java.util.HashMap;

public class Solution {

    public int countGoodRectangles(int[][] rectangles) {
        int maxLen = 0, k, count = 0;
        for (int[] rectangle : rectangles) {
            k = Math.min(rectangle[0], rectangle[1]);
            if (k > maxLen) {
                maxLen = k;
                count = 1;
            } else if (k == maxLen) {
                ++count;
            }
        }
        return count;
    }

//    public int countGoodRectangles(int[][] rectangles) {
//        HashMap<Integer, Integer> kCount = new HashMap<>();
//        int maxLen = 0, k;
//        for (int[] rectangle : rectangles) {
//            k = Math.min(rectangle[0], rectangle[1]);
//            if (k > maxLen) {
//                maxLen = k;
//            }
//            kCount.put(k, kCount.computeIfAbsent(k, key -> 0) + 1);
//        }
//        return kCount.get(maxLen);
//    }
}
